# -*- coding: utf-8 -*- 
#
# Description:
#
#  Definiton
#
#
#
# Changes:
#
# 2012-01-10
# Initial Commit
#
#
# Copyright 2010-2012, WyDev Team.
# Author: Polo35 (polo35580@hotmail.fr)
#
# Licenced under Academic Free License version 3.0
# Review WyGui README & LICENSE files for further details.

nname: 0
n 0(None)[PowerManagerModule.__init__(self, 'pygui')
self.sleeping = False
self._mute_flag = False
events_watch(self.handle)
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb75ccd0c>}
nname: 153
n 153(None)[]:
	i: 85(JA), 149(), 152()
	o: 

nname: 152
n 152(None)[]:
	i: 0(f)
	o: 153()

nname: 149
n 149(None)[]:
	i: 71(JA), 112()
	o: 153()

nname: 112
n 112(None)[log.warning('Standby is disabled due to a shutdown_command definition')
from peewee.notifier import stop
stop()
]:
	i: 49(f)
	o: 149()

nname: 85
n 85(None)[self.led.ask_standby()
self.standby()
]:
	i: 58(f)
	o: 153(JA)

nname: 71
n 71(None)[self.wakeup()
]:
	i: 58(t)
	o: 149(JA)

nname: 58
n 58(self.pm.apm_state)[]:
	i: 49(t)
	o: 71(t), 85(f)

nname: 49
n 49(config.shutdown)[]:
	i: 26(), 48()
	o: 58(t), 112(f)

nname: 48
n 48(None)[]:
	i: 15(f)
	o: 49()

nname: 26
n 26(None)[pygui_globs['demomode'].stop()
]:
	i: 15(t)
	o: 49()

nname: 15
n 15(pygui_globs['demomode'])[]:
	i: 0(t)
	o: 26(t), 48(f)

nname: 0
n 0(event.name == 'POWER')[]:
	i: 
	o: 15(t), 152(f)

nname: 153
n 153(None)[]:
	i: 85(JA), 71(JA), 112(), 0(f)
	o: 

nname: 112
n 112(None)[log.warning('Standby is disabled due to a shutdown_command definition')
from peewee.notifier import stop
stop()
]:
	i: 15(f)
	o: 153()

nname: 85
n 85(None)[self.led.ask_standby()
self.standby()
]:
	i: 58(f)
	o: 153(JA)

nname: 71
n 71(None)[self.wakeup()
]:
	i: 58(t)
	o: 153(JA)

nname: 58
n 58(self.pm.apm_state)[]:
	i: 15(t)
	o: 71(t), 85(f)

nname: 15
n 15(config.shutdown)[if pygui_globs['demomode']:
	pygui_globs['demomode'].stop()
]:
	i: 0(t)
	o: 58(t), 112(f)

nname: 0
n 0(event.name == 'POWER')[]:
	i: 
	o: 15(t), 153(f)

nname: 0
n 0(None)[if event.name == 'POWER':
	if pygui_globs['demomode']:
		pygui_globs['demomode'].stop()
	if config.shutdown:
		if self.pm.apm_state:
			self.wakeup()
		else:
			self.led.ask_standby()
			self.standby()
	else:
		log.warning('Standby is disabled due to a shutdown_command definition')
		from peewee.notifier import stop
		stop()
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb75d382c>}
nname: 88
n 88(None)[stack.back_to_home()
stack.get_root().active_univ = None
return True
]:
	i: 0(AL), 87()
	o: 

nname: 87
n 87(None)[]:
	i: 29(AF), 83()
	o: 88()

nname: 83
n 83(None)[]:
	i: 60(f), 75()
	o: 87()

nname: 75
n 75(None)[return False
continue
]:
	i: 60(t)
	o: 83()

nname: 60
n 60(isinstance(m, FirstBootMenu))[]:
	i: 51(), 59()
	o: 75(t), 83(f)

nname: 59
n 59(None)[]:
	i: 39(f)
	o: 60()

nname: 51
n 51(None)[return False
]:
	i: 39(t)
	o: 60()

nname: 39
n 39(m.hold)[for m in stack.menus_stack:
]:
	i: 29(for)
	o: 51(t), 59(f)

nname: 29
n 29(None)[]:
	i: 0(loop)
	o: 39(for), 87(AF)

nname: 0
n 0(None)[from pygui.menu.menu.firstboot import FirstBootMenu
stack = pygui_globs['menustack']
]:
	i: 
	o: 29(loop), 88(AL)

nname: 88
n 88(None)[stack.back_to_home()
stack.get_root().active_univ = None
return True
]:
	i: 0(AL), 29(AF), 39(f)
	o: 

nname: 39
n 39(None)[for m in stack.menus_stack:
if m.hold:
	return False
if isinstance(m, FirstBootMenu):
	return False
	continue
]:
	i: 29(for)
	o: 88()

nname: 29
n 29(None)[]:
	i: 0(loop)
	o: 39(for), 88(AF)

nname: 0
n 0(None)[from pygui.menu.menu.firstboot import FirstBootMenu
stack = pygui_globs['menustack']
]:
	i: 
	o: 29(loop), 88(AL)

nname: 39
n 39(None)[for m in stack.menus_stack:
	if m.hold:
		return False
	if isinstance(m, FirstBootMenu):
		return False
		continue
stack.back_to_home()
stack.get_root().active_univ = None
return True
]:
	i: 0(for)
	o: 

nname: 0
n 0(None)[from pygui.menu.menu.firstboot import FirstBootMenu
stack = pygui_globs['menustack']
]:
	i: 
	o: 39(for)

nname: 0
n 0(None)[from pygui.menu.menu.firstboot import FirstBootMenu
stack = pygui_globs['menustack']
for m in stack.menus_stack:
	if m.hold:
		return False
	if isinstance(m, FirstBootMenu):
		return False
		continue
stack.back_to_home()
stack.get_root().active_univ = None
return True
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb75d310c>}
nname: 72
n 72(None)[]:
	i: 31(), 58()
	o: 

nname: 58
n 58(None)[os.system('/sbin/reboot')
]:
	i: 0(f)
	o: 72()

nname: 31
n 31(None)[log.critical('Not!')
notifier.stop()
]:
	i: 0(t)
	o: 72()

nname: 0
n 0(platform.machine() != 'sh4')[log.critical('Rebooting the system...')
]:
	i: 
	o: 31(t), 58(f)

nname: 0
n 0(None)[log.critical('Rebooting the system...')
if platform.machine() != 'sh4':
	log.critical('Not!')
	notifier.stop()
else:
	os.system('/sbin/reboot')
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb75ccbec>}
nname: 71
n 71(None)[]:
	i: 31(), 58()
	o: 

nname: 58
n 58(None)[self.pm.apm_state = 1
]:
	i: 0(f)
	o: 71()

nname: 31
n 31(None)[log.critical('Not!')
notifier.stop()
]:
	i: 0(t)
	o: 71()

nname: 0
n 0(platform.machine() != 'sh4')[log.critical('Shutting the system down...')
]:
	i: 
	o: 31(t), 58(f)

nname: 0
n 0(None)[log.critical('Shutting the system down...')
if platform.machine() != 'sh4':
	log.critical('Not!')
	notifier.stop()
else:
	self.pm.apm_state = 1
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb75cce6c>}
nname: 71
n 71(None)[]:
	i: 31(), 58()
	o: 

nname: 58
n 58(None)[self.pm.apm_state = 1
]:
	i: 0(f)
	o: 71()

nname: 31
n 31(None)[log.critical('Not!')
notifier.stop()
]:
	i: 0(t)
	o: 71()

nname: 0
n 0(platform.machine() != 'sh4')[log.critical('Shutting the system down...')
]:
	i: 
	o: 31(t), 58(f)

nname: 0
n 0(None)[log.critical('Shutting the system down...')
if platform.machine() != 'sh4':
	log.critical('Not!')
	notifier.stop()
else:
	self.pm.apm_state = 1
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb75ccbec>}
nname: 71
n 71(None)[]:
	i: 31(), 58()
	o: 

nname: 58
n 58(None)[self.pm.apm_state = 3
]:
	i: 0(f)
	o: 71()

nname: 31
n 31(None)[log.critical('Not!')
notifier.stop()
]:
	i: 0(t)
	o: 71()

nname: 0
n 0(platform.machine() != 'sh4')[log.critical('Shutting the system down...')
]:
	i: 
	o: 31(t), 58(f)

nname: 0
n 0(None)[log.critical('Shutting the system down...')
if platform.machine() != 'sh4':
	log.critical('Not!')
	notifier.stop()
else:
	self.pm.apm_state = 3
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb75cce2c>}
nname: 76
n 76(None)[]:
	i: 60(JA), 71(), 75()
	o: 

nname: 75
n 75(None)[]:
	i: 0(f)
	o: 76()

nname: 71
n 71(None)[]:
	i: 27(f)
	o: 76()

nname: 60
n 60(None)[restore_last_universe()
]:
	i: 27(t)
	o: 76(JA)

nname: 27
n 27(ms.menus_stack[-1].type in ('switcher', 'home', 'root'))[ms = pygui_globs['menustack']
]:
	i: 0(t)
	o: 60(t), 71(f)

nname: 0
n 0('restore_last_universe' in config.plugins)[self.pm.apm_state = 0
]:
	i: 
	o: 27(t), 75(f)

nname: 0
n 0(None)[self.pm.apm_state = 0
if 'restore_last_universe' in config.plugins:
	ms = pygui_globs['menustack']
	if ms.menus_stack[-1].type in ('switcher', 'home', 'root'):
		restore_last_universe()
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb75ccf0c>}
nname: 107
n 107(None)[]:
	i: 77(AE)
	o: 

nname: 77
n 77(None)[self.led.ask_led_action(4)
PowerManagerModule.apm_ready(self)
]:
	i: 0(finally), 73()
	o: 107(AE)

nname: 73
n 73(None)[]:
	i: 46(), 72()
	o: 77()

nname: 72
n 72(None)[]:
	i: 37(f)
	o: 73()

nname: 46
n 46(None)[Mixer().toggle_mute()
self._mute_flag = False
]:
	i: 37(t)
	o: 73()

nname: 37
n 37(self._mute_flag)[]:
	i: 0(ASF)
	o: 46(t), 72(f)

nname: 0
n 0(None)[from pygui.eventmanager import EventDispatcher
EventDispatcher._disable_next_input = False
self.sleeping = False
]:
	i: 
	o: 37(ASF), 77(finally)

nname: 107
n 107(None)[]:
	i: 77(AE)
	o: 

nname: 77
n 77(None)[self.led.ask_led_action(4)
PowerManagerModule.apm_ready(self)
]:
	i: 0(finally), 37()
	o: 107(AE)

nname: 37
n 37(None)[if self._mute_flag:
	Mixer().toggle_mute()
	self._mute_flag = False
]:
	i: 0(ASF)
	o: 77()

nname: 0
n 0(None)[from pygui.eventmanager import EventDispatcher
EventDispatcher._disable_next_input = False
self.sleeping = False
]:
	i: 
	o: 37(ASF), 77(finally)

nname: 77
n 77(None)[finally:
	self.led.ask_led_action(4)
	PowerManagerModule.apm_ready(self)
]:
	i: 0()
	o: 

nname: 0
n 0(None)[from pygui.eventmanager import EventDispatcher
EventDispatcher._disable_next_input = False
self.sleeping = False
try:
	if self._mute_flag:
		Mixer().toggle_mute()
		self._mute_flag = False
]:
	i: 
	o: 77()

nname: 0
n 0(None)[from pygui.eventmanager import EventDispatcher
EventDispatcher._disable_next_input = False
self.sleeping = False
try:
	if self._mute_flag:
		Mixer().toggle_mute()
		self._mute_flag = False
finally:
	self.led.ask_led_action(4)
	PowerManagerModule.apm_ready(self)
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb75d3e2c>}
nname: 136
n 136(None)[]:
	i: 106(AE)
	o: 

nname: 106
n 106(None)[self.led.ask_led_action(3)
PowerManagerModule.apm_standby(self)
]:
	i: 0(finally), 102()
	o: 136(AE)

nname: 102
n 102(None)[]:
	i: 78(), 101()
	o: 106()

nname: 101
n 101(None)[]:
	i: 47(t)
	o: 102()

nname: 78
n 78(None)[mixer.mute()
self._mute_flag = True
]:
	i: 47(f)
	o: 102()

nname: 47
n 47(mixer.get_mute())[self._clean_stack()
mixer = Mixer()
]:
	i: 0(ASF)
	o: 78(f), 101(t)

nname: 0
n 0(None)[from pygui.eventmanager import EventDispatcher
EventDispatcher._disable_next_input = False
self.sleeping = True
ms = pygui_globs['menustack']
]:
	i: 
	o: 47(ASF), 106(finally)

nname: 136
n 136(None)[]:
	i: 106(AE)
	o: 

nname: 106
n 106(None)[self.led.ask_led_action(3)
PowerManagerModule.apm_standby(self)
]:
	i: 0(finally), 47()
	o: 136(AE)

nname: 47
n 47(None)[self._clean_stack()
mixer = Mixer()
if not mixer.get_mute():
	mixer.mute()
	self._mute_flag = True
]:
	i: 0(ASF)
	o: 106()

nname: 0
n 0(None)[from pygui.eventmanager import EventDispatcher
EventDispatcher._disable_next_input = False
self.sleeping = True
ms = pygui_globs['menustack']
]:
	i: 
	o: 47(ASF), 106(finally)

nname: 106
n 106(None)[finally:
	self.led.ask_led_action(3)
	PowerManagerModule.apm_standby(self)
]:
	i: 0()
	o: 

nname: 0
n 0(None)[from pygui.eventmanager import EventDispatcher
EventDispatcher._disable_next_input = False
self.sleeping = True
ms = pygui_globs['menustack']
try:
	self._clean_stack()
	mixer = Mixer()
	if not mixer.get_mute():
		mixer.mute()
		self._mute_flag = True
]:
	i: 
	o: 106()

nname: 0
n 0(None)[from pygui.eventmanager import EventDispatcher
EventDispatcher._disable_next_input = False
self.sleeping = True
ms = pygui_globs['menustack']
try:
	self._clean_stack()
	mixer = Mixer()
	if not mixer.get_mute():
		mixer.mute()
		self._mute_flag = True
finally:
	self.led.ask_led_action(3)
	PowerManagerModule.apm_standby(self)
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb75d3d8c>}
nname: 0
n 0(None)[from pygui.eventmanager import EventDispatcher
EventDispatcher._disable_next_input = False
self.sleeping = True
self._clean_stack()
PowerManagerModule.apm_off(self)
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb75ccd0c>}
nname: 0
n 0(None)[from pygui.eventmanager import EventDispatcher
EventDispatcher._disable_next_input = True
self.sleeping = True
self._clean_stack()
PowerManagerModule.apm_suspend(self)
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb75cce2c>}
nname: 6
n 6(None)[__metaclass__ = MetaSingleton
led = WyLed()
def __init__(self):
	PowerManagerModule.__init__(self, 'pygui')
	self.sleeping = False
	self._mute_flag = False
	events_watch(self.handle)

def handle(self, event):
	if event.name == 'POWER':
		if pygui_globs['demomode']:
			pygui_globs['demomode'].stop()
		if config.shutdown:
			if self.pm.apm_state:
				self.wakeup()
			else:
				self.led.ask_standby()
				self.standby()
		else:
			log.warning('Standby is disabled due to a shutdown_command definition')
			from peewee.notifier import stop
			stop()

def _clean_stack(self):
	from pygui.menu.menu.firstboot import FirstBootMenu
	stack = pygui_globs['menustack']
	for m in stack.menus_stack:
		if m.hold:
			return False
		if isinstance(m, FirstBootMenu):
			return False
			continue
	stack.back_to_home()
	stack.get_root().active_univ = None
	return True

def reboot(self):
	log.critical('Rebooting the system...')
	if platform.machine() != 'sh4':
		log.critical('Not!')
		notifier.stop()
	else:
		os.system('/sbin/reboot')

def standby(self):
	log.critical('Shutting the system down...')
	if platform.machine() != 'sh4':
		log.critical('Not!')
		notifier.stop()
	else:
		self.pm.apm_state = 1

def real_standby(self):
	log.critical('Shutting the system down...')
	if platform.machine() != 'sh4':
		log.critical('Not!')
		notifier.stop()
	else:
		self.pm.apm_state = 1

def off(self):
	log.critical('Shutting the system down...')
	if platform.machine() != 'sh4':
		log.critical('Not!')
		notifier.stop()
	else:
		self.pm.apm_state = 3

def wakeup(self):
	self.pm.apm_state = 0
	if 'restore_last_universe' in config.plugins:
		ms = pygui_globs['menustack']
		if ms.menus_stack[-1].type in ('switcher', 'home', 'root'):
			restore_last_universe()

def apm_ready(self):
	from pygui.eventmanager import EventDispatcher
	EventDispatcher._disable_next_input = False
	self.sleeping = False
	try:
		if self._mute_flag:
			Mixer().toggle_mute()
			self._mute_flag = False
	finally:
		self.led.ask_led_action(4)
		PowerManagerModule.apm_ready(self)

def apm_standby(self):
	from pygui.eventmanager import EventDispatcher
	EventDispatcher._disable_next_input = False
	self.sleeping = True
	ms = pygui_globs['menustack']
	try:
		self._clean_stack()
		mixer = Mixer()
		if not mixer.get_mute():
			mixer.mute()
			self._mute_flag = True
	finally:
		self.led.ask_led_action(3)
		PowerManagerModule.apm_standby(self)

def apm_off(self):
	from pygui.eventmanager import EventDispatcher
	EventDispatcher._disable_next_input = False
	self.sleeping = True
	self._clean_stack()
	PowerManagerModule.apm_off(self)

def apm_suspend(self):
	from pygui.eventmanager import EventDispatcher
	EventDispatcher._disable_next_input = True
	self.sleeping = True
	self._clean_stack()
	PowerManagerModule.apm_suspend(self)

]:
	i: 
	o: 

self.nodes: {6: <unpyclib.structure.node instance at 0xb75cc14c>}
nname: 134
n 134(None)[]:
	i: 37(JA), 96(JA), 130(), 133()
	o: 

nname: 133
n 133(None)[]:
	i: 0(f)
	o: 134()

nname: 130
n 130(None)[]:
	i: 128(AE)
	o: 134()

nname: 128
n 128(None)[]:
	i: 86(f)
	o: 130(AE)

nname: 96
n 96(None)[#, e
log.warning('restore_last_universe failed:')
PRINT_EXCEPTION(e)
]:
	i: 86(t)
	o: 134(JA)

nname: 86
n 86(<dummy_ex3> EXC_MATCH Exception)[]:
	i: 23(except)
	o: 96(t), 128(f)

nname: 37
n 37(None)[ms.back_to_home()
home_menu = ms.get_home()
home_menu.select(last_universe)
home_menu.execute_selected()
]:
	i: 23(try)
	o: 134(JA)

nname: 23
n 23(None)[ms = pygui_globs['menustack']
]:
	i: 0(t)
	o: 37(try), 86(except)

nname: 0
n 0(last_universe)[last_universe = config.user_config['advanced']['last_universe']
]:
	i: 
	o: 23(t), 133(f)

nname: 134
n 134(None)[]:
	i: 37(JA), 96(JA), 86(f), 128(AE), 0(f)
	o: 

nname: 96
n 96(None)[#, e
log.warning('restore_last_universe failed:')
PRINT_EXCEPTION(e)
]:
	i: 86(t)
	o: 134(JA)

nname: 86
n 86(<dummy_ex3> EXC_MATCH Exception)[]:
	i: 23(except)
	o: 96(t), 134(f)

nname: 37
n 37(None)[ms.back_to_home()
home_menu = ms.get_home()
home_menu.select(last_universe)
home_menu.execute_selected()
]:
	i: 23(try)
	o: 134(JA)

nname: 23
n 23(None)[ms = pygui_globs['menustack']
]:
	i: 0(t)
	o: 37(try), 86(except)

nname: 0
n 0(last_universe)[last_universe = config.user_config['advanced']['last_universe']
]:
	i: 
	o: 23(t), 134(f)

nname: 134
n 134(None)[]:
	i: 86(f), 0(f)
	o: 

nname: 86
n 86(None)[except Exception, e:
	log.warning('restore_last_universe failed:')
	PRINT_EXCEPTION(e)
]:
	i: 23()
	o: 134(JA)

nname: 23
n 23(None)[ms = pygui_globs['menustack']
try:
	ms.back_to_home()
	home_menu = ms.get_home()
	home_menu.select(last_universe)
	home_menu.execute_selected()
]:
	i: 0(t)
	o: 86()

nname: 0
n 0(last_universe)[last_universe = config.user_config['advanced']['last_universe']
]:
	i: 
	o: 23(t), 134(f)

nname: 134
n 134(None)[]:
	i: 23(f), 0(f)
	o: 

nname: 23
n 23(None)[ms = pygui_globs['menustack']
try:
	ms.back_to_home()
	home_menu = ms.get_home()
	home_menu.select(last_universe)
	home_menu.execute_selected()
except Exception, e:
	log.warning('restore_last_universe failed:')
	PRINT_EXCEPTION(e)
]:
	i: 0(t)
	o: 134(JA)

nname: 0
n 0(last_universe)[last_universe = config.user_config['advanced']['last_universe']
]:
	i: 
	o: 23(t), 134(f)

nname: 0
n 0(None)[last_universe = config.user_config['advanced']['last_universe']
if last_universe:
	ms = pygui_globs['menustack']
	try:
		ms.back_to_home()
		home_menu = ms.get_home()
		home_menu.select(last_universe)
		home_menu.execute_selected()
	except Exception, e:
		log.warning('restore_last_universe failed:')
		PRINT_EXCEPTION(e)
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb75cc08c>}
nname: 0
n 0(None)[PowerManager().reboot()
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb75c6bec>}
nname: 0
n 0(None)[from __future__ import absolute_import
import os
import platform
from peewee.debug import GET_LOGGER, PRINT_EXCEPTION
from peewee.powerutils import PowerManagerModule
from peewee.misc_utils import MetaSingleton
from peewee import notifier
from pygui.shared import pygui_globs
log = GET_LOGGER(__name__)
from peewee.notifier import events_watch
from pygui.eventmanager import EventDispatcher
from pygui.shared import pygui_globs
from pygui import config
from .mixer import Mix as Mixer
from pygui.facilities.wylight import WyLed
class PowerManager(PowerManagerModule):
	__metaclass__ = MetaSingleton
	led = WyLed()
	def __init__(self):
		PowerManagerModule.__init__(self, 'pygui')
		self.sleeping = False
		self._mute_flag = False
		events_watch(self.handle)

	def handle(self, event):
		if event.name == 'POWER':
			if pygui_globs['demomode']:
				pygui_globs['demomode'].stop()
			if config.shutdown:
				if self.pm.apm_state:
					self.wakeup()
				else:
					self.led.ask_standby()
					self.standby()
			else:
				log.warning('Standby is disabled due to a shutdown_command definition')
				from peewee.notifier import stop
				stop()

	def _clean_stack(self):
		from pygui.menu.menu.firstboot import FirstBootMenu
		stack = pygui_globs['menustack']
		for m in stack.menus_stack:
			if m.hold:
				return False
			if isinstance(m, FirstBootMenu):
				return False
				continue
		stack.back_to_home()
		stack.get_root().active_univ = None
		return True

	def reboot(self):
		log.critical('Rebooting the system...')
		if platform.machine() != 'sh4':
			log.critical('Not!')
			notifier.stop()
		else:
			os.system('/sbin/reboot')

	def standby(self):
		log.critical('Shutting the system down...')
		if platform.machine() != 'sh4':
			log.critical('Not!')
			notifier.stop()
		else:
			self.pm.apm_state = 1

	def real_standby(self):
		log.critical('Shutting the system down...')
		if platform.machine() != 'sh4':
			log.critical('Not!')
			notifier.stop()
		else:
			self.pm.apm_state = 1

	def off(self):
		log.critical('Shutting the system down...')
		if platform.machine() != 'sh4':
			log.critical('Not!')
			notifier.stop()
		else:
			self.pm.apm_state = 3

	def wakeup(self):
		self.pm.apm_state = 0
		if 'restore_last_universe' in config.plugins:
			ms = pygui_globs['menustack']
			if ms.menus_stack[-1].type in ('switcher', 'home', 'root'):
				restore_last_universe()

	def apm_ready(self):
		from pygui.eventmanager import EventDispatcher
		EventDispatcher._disable_next_input = False
		self.sleeping = False
		try:
			if self._mute_flag:
				Mixer().toggle_mute()
				self._mute_flag = False
		finally:
			self.led.ask_led_action(4)
			PowerManagerModule.apm_ready(self)

	def apm_standby(self):
		from pygui.eventmanager import EventDispatcher
		EventDispatcher._disable_next_input = False
		self.sleeping = True
		ms = pygui_globs['menustack']
		try:
			self._clean_stack()
			mixer = Mixer()
			if not mixer.get_mute():
				mixer.mute()
				self._mute_flag = True
		finally:
			self.led.ask_led_action(3)
			PowerManagerModule.apm_standby(self)

	def apm_off(self):
		from pygui.eventmanager import EventDispatcher
		EventDispatcher._disable_next_input = False
		self.sleeping = True
		self._clean_stack()
		PowerManagerModule.apm_off(self)

	def apm_suspend(self):
		from pygui.eventmanager import EventDispatcher
		EventDispatcher._disable_next_input = True
		self.sleeping = True
		self._clean_stack()
		PowerManagerModule.apm_suspend(self)



def restore_last_universe():
	last_universe = config.user_config['advanced']['last_universe']
	if last_universe:
		ms = pygui_globs['menustack']
		try:
			ms.back_to_home()
			home_menu = ms.get_home()
			home_menu.select(last_universe)
			home_menu.execute_selected()
		except Exception, e:
			log.warning('restore_last_universe failed:')
			PRINT_EXCEPTION(e)

def reboot():
	PowerManager().reboot()

]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb75bf9ac>}
from __future__ import absolute_import
import os
import platform
from peewee.debug import GET_LOGGER, PRINT_EXCEPTION
from peewee.powerutils import PowerManagerModule
from peewee.misc_utils import MetaSingleton
from peewee import notifier
from pygui.shared import pygui_globs
log = GET_LOGGER(__name__)
from peewee.notifier import events_watch
from pygui.eventmanager import EventDispatcher
from pygui.shared import pygui_globs
from pygui import config
from .mixer import Mix as Mixer
from pygui.facilities.wylight import WyLed
class PowerManager(PowerManagerModule):
	__metaclass__ = MetaSingleton
	led = WyLed()
	def __init__(self):
		PowerManagerModule.__init__(self, 'pygui')
		self.sleeping = False
		self._mute_flag = False
		events_watch(self.handle)

	def handle(self, event):
		if event.name == 'POWER':
			if pygui_globs['demomode']:
				pygui_globs['demomode'].stop()
			if config.shutdown:
				if self.pm.apm_state:
					self.wakeup()
				else:
					self.led.ask_standby()
					self.standby()
			else:
				log.warning('Standby is disabled due to a shutdown_command definition')
				from peewee.notifier import stop
				stop()

	def _clean_stack(self):
		from pygui.menu.menu.firstboot import FirstBootMenu
		stack = pygui_globs['menustack']
		for m in stack.menus_stack:
			if m.hold:
				return False
			if isinstance(m, FirstBootMenu):
				return False
				continue
		stack.back_to_home()
		stack.get_root().active_univ = None
		return True

	def reboot(self):
		log.critical('Rebooting the system...')
		if platform.machine() != 'sh4':
			log.critical('Not!')
			notifier.stop()
		else:
			os.system('/sbin/reboot')

	def standby(self):
		log.critical('Shutting the system down...')
		if platform.machine() != 'sh4':
			log.critical('Not!')
			notifier.stop()
		else:
			self.pm.apm_state = 1

	def real_standby(self):
		log.critical('Shutting the system down...')
		if platform.machine() != 'sh4':
			log.critical('Not!')
			notifier.stop()
		else:
			self.pm.apm_state = 1

	def off(self):
		log.critical('Shutting the system down...')
		if platform.machine() != 'sh4':
			log.critical('Not!')
			notifier.stop()
		else:
			self.pm.apm_state = 3

	def wakeup(self):
		self.pm.apm_state = 0
		if 'restore_last_universe' in config.plugins:
			ms = pygui_globs['menustack']
			if ms.menus_stack[-1].type in ('switcher', 'home', 'root'):
				restore_last_universe()

	def apm_ready(self):
		from pygui.eventmanager import EventDispatcher
		EventDispatcher._disable_next_input = False
		self.sleeping = False
		try:
			if self._mute_flag:
				Mixer().toggle_mute()
				self._mute_flag = False
		finally:
			self.led.ask_led_action(4)
			PowerManagerModule.apm_ready(self)

	def apm_standby(self):
		from pygui.eventmanager import EventDispatcher
		EventDispatcher._disable_next_input = False
		self.sleeping = True
		ms = pygui_globs['menustack']
		try:
			self._clean_stack()
			mixer = Mixer()
			if not mixer.get_mute():
				mixer.mute()
				self._mute_flag = True
		finally:
			self.led.ask_led_action(3)
			PowerManagerModule.apm_standby(self)

	def apm_off(self):
		from pygui.eventmanager import EventDispatcher
		EventDispatcher._disable_next_input = False
		self.sleeping = True
		self._clean_stack()
		PowerManagerModule.apm_off(self)

	def apm_suspend(self):
		from pygui.eventmanager import EventDispatcher
		EventDispatcher._disable_next_input = True
		self.sleeping = True
		self._clean_stack()
		PowerManagerModule.apm_suspend(self)



def restore_last_universe():
	last_universe = config.user_config['advanced']['last_universe']
	if last_universe:
		ms = pygui_globs['menustack']
		try:
			ms.back_to_home()
			home_menu = ms.get_home()
			home_menu.select(last_universe)
			home_menu.execute_selected()
		except Exception, e:
			log.warning('restore_last_universe failed:')
			PRINT_EXCEPTION(e)

def reboot():
	PowerManager().reboot()

